//#include "gpio_device.h"
#include "uart_device.h"
//#include "timer_device.h"
#include "my_errno.h"
#include <stdio.h>

#ifndef NULL
#define NULL (void *)0
#endif



PUARTDevice ptUART4 = NULL;


int bsp_moduleInit(void)
{

	ptUART4 =GetUARTDevice("uart4");
	if (NULL == ptUART4)
		return -EINVAL;
	ptUART4->Init(ptUART4);

	return ESUCCESS;
}


//---------------------获取--------------------



//---------------------设置--------------------


//---------------------通信--------------------
int bsp_debugCommRead(uint8_t *pData, uint16_t timeoutMS)
{
	int res = ESUCCESS;
	if (NULL == ptUART4)
		return res;

	res =ptUART4->Recv(ptUART4, pData, timeoutMS);
	return res;
}

int bsp_debugComWrite(uint8_t *pData, uint16_t len, uint16_t timeoutMS)
{
	int res = ESUCCESS;
	if (NULL == ptUART4)
		return res;

	res =ptUART4->Send(ptUART4, (unsigned char *)pData, (int)len, (int)timeoutMS);
	return res;
}

#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

//STM32cubeIDE下
PUTCHAR_PROTOTYPE
{
    //HAL_UART_Transmit(&huart3 , (uint8_t *)&ch, 1,0x200);
	bsp_debugComWrite((uint8_t *)&ch, 1, 1000);
    return ch;
}


//int fputc(int ch, FILE *f)  
//{
//	bsp_debugComWrite((uint8_t *)&ch, 1, 1000);
//	return ch;
//}


